/*
 * GeoEquilibrator.h
 *
 *  Created on: 17 Oct 2011
 *      Author: allan
 */

#ifndef GEOEQUILIBRATOR_H_
#define GEOEQUILIBRATOR_H_

// C++ includes
#include <string>
using namespace std;

// GeoReact includes
#include "Geochemistry/GeoSystem.h"
#include "Core/EquilibriumConditions.h"
#include "Core/EquilibriumSolver.h"

// GeoReact forward declarations
class GeoState;

class GeoEquilibrator
{
public:
	GeoEquilibrator(const GeoSystem& geosystem);
	
	void ImposeSpeciesMass(const string& species, double mass);
	
	void ImposeSpeciesActivity(const string& species, double activity);
	
	void ImposeElementMass(const string& element, double mass);
	
	void ImposeAcidity(double pH);	
	
	void ImposePartialPressure(const string& gas, double Pg);
	
	void ImposeChargeBalance();
	
	void ResetConditions();
	
	void SetCompositionGuess(const string& species, double mass);
	
	const EquilibriumSolver::Diagnostic GetDiagnostic() const;
	
	void Equilibrate(GeoState& geostate);
	
	void Equilibrate(GeoState& geostate, const VectorXd& nGuess);
	
private:
	/// The multiphase instance
	const Multiphase& multiphase;
	
	/// The system of equilibrium-controlled reactions
	const ReactionSystem& eReactions;
	
	/// The equilibrium conditions of the equilibrium problem
	vector<EquilibriumCondition> eConditions;
	
	/// The equilibrium solver to solve the equilibrium problem
	EquilibriumSolver eSolver;
	
	/// The initial guess for the system composition
	VectorXd n;
	
	/// The diagnostic of the last equilibrium calculation 
	EquilibriumSolver::Diagnostic diagnostic;
};

#endif /* GEOEQUILIBRATOR_H_ */
